let t = require;
let  e = module
let  o =  e.exports;
 o.default =  e.exports;

                'use strict';
                console.log("start"),
                    Object.defineProperty(o, '__esModule', {
                        value: !0
                    }),
                    (o.MergeMrg = o.GridItemData = void 0);
                var n = t('SoldierItemCfg'),
                    i = t('BattleUtils'),
                    r = (function() {
                        function t(t, e, o) {
                            this.init(t), (this._col = e), (this._row = o);
                        }
                        return (
                            (t.prototype.init = function(t) {
                                this._data = t;
                            }),
                            Object.defineProperty(t.prototype, 'data', {
                                get: function get() {
                                    return this._data;
                                },
                                enumerable: !1,
                                configurable: !0
                            }),
                            Object.defineProperty(t.prototype, 'col', {
                                get: function get() {
                                    return this._col;
                                },
                                enumerable: !1,
                                configurable: !0
                            }),
                            Object.defineProperty(t.prototype, 'row', {
                                get: function get() {
                                    return this._row;
                                },
                                enumerable: !1,
                                configurable: !0
                            }),
                            t
                        );
                    })();
                o.GridItemData = r;
                var a = (function() {
                    function t() {}
                    return (
                        (t.init = function(t, e) {
                            (this.grids = t), (this.view = e);
                        }),
                        (t.getMerges = function(t) {
                            var e = [t],
                                o = {},
                                n = 0;
                            for (o[100 * t.row + t.col] = !0; n < e.length;) {
                                for (var r = 0; r < i.default.Location.length; r++) {
                                    var a = i.default.Location[r],
                                        s = e[n].col + a.x,
                                        c = e[n].row + a.y;
                                    if (this.grids[c] && !o[100 * c + s]) {
                                        var l = this.grids[c][s];
                                        l &&
                                            l.data &&
                                            l.data.id == t.data.id &&
                                            ((o[100 * c + s] = !0), e.push(l));
                                    }
                                }
                                n++;
                            }
                            return e.length >= i.default.MergeCount ? e : null;
                        }),
                        (t.calcStep = function(t) {
                            for (var e, o = [t], i = t.data.level; o.length > 0;) {
                                if (
                                    ((e = o.shift()), !n.SoldierItemCfg.ins.isMaxLevel(e.data))
                                ) {
                                    var a = this.getMerges(e);
                                    if (a)
                                        for (var s = 1; s < a.length; s++) {
                                            var c = new r(a[s].data, a[s].col, a[s].row);
                                            c.init(
                                                    n.SoldierItemCfg.ins.getDataByTypeLevel(
                                                        c.data.type,
                                                        c.data.level + 1
                                                    )
                                                ),
                                                o.push(c);
                                        }
                                }
                            }
                            return e.data.level - i;
                        }),
                        (t.getCanMerge = function(t) {
                            if (t && t.data) {
                                var e = this.getMerges(t);
                                if (e && e.length >= i.default.MergeCount) {
                                    for (var o = 0, a = 0, s = 0; s < e.length; s++) {
                                        var c = n.SoldierItemCfg.ins.getDataByTypeLevel(
                                                e[s].data.type,
                                                e[s].data.level + 1
                                            ),
                                            l = this.calcStep(new r(c, e[s].col, e[s].row));
                                        l > o && ((a = s), (o = l));
                                    }
                                    if (a > 0) {
                                        var u = e[0];
                                        (e[0] = e[a]), (e[a] = u);
                                    }
                                    return e;
                                }
                            }
                            return null;
                        }),
                        (t.getCanMergeLeastLevelItems = function(t) {
                            for (var e = [], o = 0; o < this.grids.length; o++) {
                                for (var n = this.grids[o], i = 0; i < n.length; i++) {
                                    var r = n[i];
                                    r.data &&
                                        r.data.level >= t &&
                                        this.checkCanMerge(r) &&
                                        e.push(r.data);
                                }
                            }
                            return e;
                        }),
                        (t.checkCanMerge = function(t) {
                            if (t && t.data && t.data.type <= 3)
                                for (var e = 0; e < i.default.Location.length; e++) {
                                    var o = i.default.Location[e],
                                        n = t.col + o.x,
                                        r = t.row + o.y;
                                    if (this.grids[r]) {
                                        var a = this.grids[r][n];
                                        if (a && a.data == t.data) return !0;
                                    }
                                }
                            return !1;
                        }),
                        (t.calcMergeWeight = function(t, e) {
                            var o = 0;
                            if (e)
                                for (var n = 0; n < i.default.Location.length; n++) {
                                    var r = i.default.Location[n],
                                        a = e.col + r.x,
                                        s = e.row + r.y;
                                    if (this.grids[s]) {
                                        var c = this.grids[s][a];
                                        c &&
                                            (c.data ?
                                                c.data.type == t.type &&
                                                c.data.level != t.level &&
                                                (o += 1e-4 * (100 - Math.abs(c.data.level - t.level))) :
                                                (o += 1e-5));
                                    }
                                }
                            return o;
                        }),
                        (t.calcSameWeight = function(t, e) {
                            var o = 0;
                            if (e)
                                for (var n = 0; n < i.default.Location.length; n++) {
                                    var r = i.default.Location[n],
                                        a = e.col + r.x,
                                        s = e.row + r.y;
                                    if (this.grids[s]) {
                                        var c = this.grids[s][a];
                                        c &&
                                            (c.data ?
                                                c.data.type == t.type &&
                                                (o +=
                                                    1e-4 *
                                                    (1e3 - 48 * Math.abs(c.data.level - t.level))) :
                                                (o += 1e-5));
                                    }
                                }
                            return o;
                        }),
                        (t.calcEmptyWeight = function(t, e) {
                            var o = 0;
                            if (e)
                                for (var n = 0; n < i.default.Location.length; n++) {
                                    var r = i.default.Location[n],
                                        a = e.col + r.x,
                                        s = e.row + r.y;
                                    if (this.grids[s]) {
                                        var c = this.grids[s][a];
                                        c && null == c.data && (o += 1e-4);
                                    }
                                }
                            return o;
                        }),
                        (t.getCanMergeLocation = function(t) {
                            for (
                                var e = [], o = [], n = [], a = 0; a < this.grids.length; a++
                            ) {
                                for (var s = this.grids[a], c = 0; c < s.length; c++) {
                                    if (null == (_ = s[c]).data) o.push(_);
                                    else if (_.data == t) {
                                        e.push(_);
                                        for (var l = 0; l < 2; l++) {
                                            for (var u = 0; u < i.default.Location.length; u++) {
                                                var h = i.default.Location[u],
                                                    p = _.col + h.x + h.x * l,
                                                    f = _.row + h.y + h.y * l;
                                                this.grids[f] &&
                                                    (m = this.grids[f][p]) &&
                                                    m.data &&
                                                    m.data == t &&
                                                    e.push(m);
                                            }
                                        }
                                        0 == n.length ? n.push(_) : n.unshift(_);
                                    } else
                                        _.data.type == t.type &&
                                        (0 == n.length ?
                                            n.push(_) :
                                            Math.abs(_.data.level - t.level) >
                                            Math.abs(n[0].data.level - t.level) ?
                                            n.push(_) :
                                            n.unshift(_));
                                }
                            }
                            var d,
                                g = 0;
                            if (e.length >= i.default.MergeCount - 1)
                                for (u = 0; u < e.length; u++) {
                                    for (
                                        var _ = e[u], y = 0; y < i.default.Location.length; y++
                                    ) {
                                        if (
                                            ((h = i.default.Location[y]),
                                                (c = _.col + h.x),
                                                (a = _.row + h.y),
                                                this.grids[a] && (m = this.grids[a][c]) && null == m.data)
                                        ) {
                                            var C = this.calcStep(new r(t, m.col, m.row));
                                            g < C + (v = this.calcMergeWeight(t, m)) &&
                                                ((g = C + v), (d = m));
                                        }
                                    }
                                }
                            if (null == d)
                                for (g = 0, u = 0; u < n.length; u++) {
                                    for (_ = n[u], y = 0; y < i.default.Location.length; y++) {
                                        var m;
                                        (h = i.default.Location[y]),
                                        (c = _.col + h.x),
                                        (a = _.row + h.y),
                                        this.grids[a] &&
                                            (m = this.grids[a][c]) &&
                                            null == m.data &&
                                            g < (v = this.calcSameWeight(t, m)) &&
                                            ((g = v), (d = m));
                                    }
                                }
                            if (null == d)
                                for (g = 0, u = 0; u < o.length; u++) {
                                    var v;
                                    (_ = o[u]),
                                    g < (v = this.calcEmptyWeight(t, _)) && ((g = v), (d = _));
                                }
                            return d;
                        }),
                        t
                    );
                })();
                (o.MergeMrg = a), console.log("end");
            module.exports =  e.exports;